package com.xuhai.blog19.admin.controller;

import com.xuhai.blog19.admin.entity.CommentEntity;
import com.xuhai.blog19.admin.service.CommentService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/2/10/010
 */
@RestController
@RequestMapping("/admin/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/page")
    public R page(int page, int limit, CommentEntity comment) {
        return R.ok().data(commentService.getPage(page, limit, comment));
    }

    @GetMapping("/info/{commentId}")
    public R info(@PathVariable Integer commentId) {
        return R.ok().data(commentService.getById(commentId));
    }

    @PostMapping(value = {"/update", "/status"})
    public R update(@RequestBody CommentEntity comment) {
        commentService.saveOrUpdate(comment);
        return R.ok();
    }

    @DeleteMapping("/delete/{commentId}")
    public R delete(@PathVariable Integer commentId) {
        commentService.removeById(commentId);
        return R.ok();
    }
}
